package cn.edu.hqu.cst.android.xzy.xzy;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    public static int MODE=MODE_PRIVATE;
    public static final String PREFERENCE_NAME="SaveSetting";
    Button btnLogin;
    EditText etAccount,etPassword;
    SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnLogin=findViewById(R.id.btn_login);
        etAccount=findViewById(R.id.account_input);
        etPassword=findViewById(R.id.password_input);
        /**完成代码***/
        sharedPreferences = getSharedPreferences("massage", Context.MODE_PRIVATE);
        String name = sharedPreferences.getString("name", "");
        String password = sharedPreferences.getString("password", "");
        etAccount.setText(name);
        etPassword.setText(password);

    }

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.btn_login:
                /**完成代码***/
                String account = etAccount.getText().toString();
                String password = etPassword.getText().toString();
                //String account = sharedPreferences.getString("etAccount",null);
                //String password = sharedPreferences.getString("etPassword",null);
                if("admin".equals(account)&&"123456".equals(password)){
                    SharedPreferences.Editor editor= sharedPreferences.edit();
                        editor.putBoolean("remenberpassword",true);
                        editor.putString("account",account);
                        editor.putString("password",password);
                    editor.commit();
                    finish();
                }else {
                    Toast.makeText(this,"账号或密码有误", Toast.LENGTH_LONG).show();

                }
                break;

        }
    }
}